<template>
<el-dialog :visible.sync="isShow" width="1000px">
  <el-descriptions title="订单详情" :column="1" direction="vertical" border size='medium'>
    <el-descriptions-item label="基本信息">
      <el-form :inline="true">
        <el-form-item label="订单编号：" style="width:40%"> {{ itemModel.orderId }} </el-form-item>
        <el-form-item label="发货时间：" style="width:40%"> {{ getfrmTime(itemModel.createTime) }} </el-form-item>
        <el-form-item label="下单时间：" style="width:40%"> {{ getfrmTime(itemModel.createTime) }} </el-form-item>
        <el-form-item label="付款时间：" style="width:40%"> {{ itemModel.payTime?getfrmTime(itemModel.payTime):'无' }} </el-form-item>
        <el-form-item label="发货类型：" style="width:40%"> {{ sendTypeDict[itemModel.sendType] }} </el-form-item>
        <el-form-item label="买家留言：" style="width:40%"> {{ itemModel.remark?itemModel.remark:'无' }} </el-form-item>
      </el-form>
    </el-descriptions-item>
  </el-descriptions>
  <el-descriptions title="" :column="4" direction="vertical" border size='medium'>
    <el-descriptions-item label="物流信息" :labelStyle="{width: '400px'}">
      <template v-if="itemModel.orderStatus=='WAIT_SEND'">
        <el-form :model="itemModel" ref="itemModel" label-width="90px" label-position="right">
          <el-form-item label="收货人：" prop="contactName">
            <el-input v-model="itemModel.addrinfo.contactName" placeholder="收货人" clearable style="width: 200px;"></el-input>
          </el-form-item>
          <el-form-item label="联系电话：" prop="contactPhone">
            <el-input v-model="itemModel.addrinfo.contactPhone" placeholder="联系电话" clearable style="width: 200px;"></el-input>
          </el-form-item>
          <el-form-item label="详细地址：" prop="detailAddr">
            <el-input v-model="itemModel.addrinfo.addrInfo" placeholder="详细地址" clearable style="width: 200px;"></el-input>
          </el-form-item>
          <el-form-item label="快递公司" prop="expressageCompany">
            <el-input v-model="itemModel.expressageinfo.expressageCompany" placeholder="请选择快递公司" clearable style="width: 200px;"></el-input>
          </el-form-item>
          <el-form-item label="快递单号" prop="expressageNum" style="margin-top: 10px;">
            <el-input v-model="itemModel.expressageinfo.expressageNum" placeholder="请输入快递单号" clearable style="width: 200px;"></el-input>
          </el-form-item>
          <el-form-item label="" style="margin-top: 10px;">
            <el-button type="primary" @click="updateExpressageNum" >保存</el-button>
          </el-form-item>
        </el-form>
       </template>
      <template v-else>
        <el-form label-width="90px">
          <el-form-item label="收货人："> {{ itemModel.addrinfo.contactName }} </el-form-item>
          <el-form-item label="联系电话："> {{ itemModel.addrinfo.contactPhone }} </el-form-item>
          <el-form-item label="收货地址：">  {{ itemModel.addrinfo.addrInfo }} </el-form-item>
        </el-form>
        <el-form :model="itemModel" ref="itemModel" label-width="90px" label-position="right">
          <el-form-item label="快递公司" prop="expressageCompany">
            <el-input v-model="itemModel.expressageinfo.expressageCompany" placeholder="请选择快递公司" clearable style="width: 200px;"></el-input>
          </el-form-item>
          <el-form-item label="快递单号" prop="expressageNum" style="margin-top: 10px;">
            <el-input v-model="itemModel.expressageinfo.expressageNum" placeholder="请输入快递单号" clearable style="width: 200px;"></el-input>
          </el-form-item>
          <el-form-item label="" style="margin-top: 10px;">
            <el-button type="primary" @click="updateExpressageNum" >保存</el-button>
          </el-form-item>
        </el-form>
      </template>
       
        
    </el-descriptions-item>
    <el-descriptions-item label="支付信息">
        <el-form>
            <el-form-item label="实付金额："> {{ itemModel.realPay }} </el-form-item>
            <el-form-item label="付款方式："> {{ paywayDict[itemModel.payway] }} </el-form-item>
            <el-form-item label="付款时间："> {{ itemModel.payTime?itemModel.payTime.slice(0, 19).replace('T', ' '):'无' }} </el-form-item>
        </el-form>
    </el-descriptions-item>
    <el-descriptions-item label="买家信息">
        <el-form>
            <el-form-item label="买家昵称："> {{ itemModel.userModel.nickname?itemModel.userModel.nickname:'未设置' }} </el-form-item>
            <el-form-item label="买家ID："> {{ itemModel.userModel.code }} </el-form-item>
            <el-form-item label="买家手机号："> {{ itemModel.userModel.phone }} </el-form-item>
        </el-form>
    </el-descriptions-item>
  </el-descriptions>
  <el-descriptions title="" :column="1" direction="vertical" border size='medium'>
    <el-descriptions-item label="商品信息">
      <el-table :data="itemModel.itemList" size='medium'>
            <el-table-column prop="cover" label="商品图片" show-overflow-tooltip>
                <template slot-scope="scope"><img width="50" height="50" :src="scope.row.coverUrl"></template>
            </el-table-column>
            <el-table-column prop="itemName" label="商品名称" show-overflow-tooltip></el-table-column>
            <el-table-column prop="payCount" label="数量" show-overflow-tooltip></el-table-column>
            <el-table-column prop="specValues" label="规格" show-overflow-tooltip>
              <template slot-scope="{index, row}">
                {{ getSpecs_sel(row.specValues) }}
              </template>
            </el-table-column>
        </el-table>
    </el-descriptions-item>
  </el-descriptions>
  <el-descriptions title="" :column="1" direction="vertical" border size='medium' v-if="itemModel.scene == 'item'">
    <el-descriptions-item label="分佣信息">
      <el-table :data="fundOrderList" size='medium'>
            <el-table-column label="订单ID" prop="orderId" :show-overflow-tooltip="true" width="180px"/>
            <el-table-column label="会员ID" prop="userModel.code" :show-overflow-tooltip="true"/>
            <el-table-column label="奖项类型" prop="scene" :show-overflow-tooltip="true">
                <template slot-scope="scope">
                    <div>{{typesOptions['scene'][scope.row.scene]}}</div>
                </template>
            </el-table-column>
            <el-table-column label="积分" prop="money" :show-overflow-tooltip="true"/>
            <el-table-column label="状态" prop="orderStatus" :show-overflow-tooltip="true">
                <template>
                    已到账
                </template>
            </el-table-column>
        </el-table>
    </el-descriptions-item>
  </el-descriptions>
</el-dialog>
</template>

<script>
import {time} from '@/utils/time.js'
import {  request_post, request_get } from '@/api/interface/operate.js'
export default {
  components: {
  },
  data() {
    return {
        isShow: false,
        searchParams: {},
        itemModel: {addrinfo:{}, userModel:{}, expressageinfo: {}},
        itemList: [],
        fundOrderList: [],
        examineGradeOptions: [],
        examineGradeOptions_high: [],
        statusDict: {'1': '在售', '0': "下架"},
        sendTypeDict: {'expressage': '快递', 'selfPickup': '自提', 'noSend': '无需发货'},
        typesOptions: {},
        paywayDict: {'wxpay': '微信支付', 'alipay': '支付宝支付', 'incomes': '积分支付', 'incomeLocked': '专项积分支付', 'incomeAndIncomeLocked': '积分组合支付',  'hxhTicket': '豪享券'},
        
    }
  },
  created(){
  },
  methods:{
    show(){
      this.isShow = true
      this.findInMoneyList()
      this.getFieldListOptionByTableKey()
    },
    close(){
        this.isShow = false
    },
    getFieldListOptionByTableKey(){
      request_post('/interface/form/getFieldListOptionByTableKey/', {
        tableKey: 'system_walletrecord'
      }).then(res => {
        if(res.data.code == 10000){
          this.typesOptions = res.data.data
        }
      })
    },
    findInMoneyList() {
        this.searchParams.orderId = this.itemModel.orderId
        request_get('/system/walletRecord/',this.searchParams).then(res => {
        if(res.data.code == 10000){
          this.totalSize = res.data.data.total_count
          this.fundOrderList = res.data.data.list
          this.fundOrderList.forEach(elem=>{
              elem.createTime = elem.createTime.slice(0, 19).replace('T', ' ')
          })
        }
      });
    },
    updateExpressageNum(){
      var form = {}
      form.orderId = this.itemModel.orderId
      form.expressageinfo = JSON.stringify(this.itemModel.expressageinfo)
      if(this.itemModel.orderStatus=='WAIT_SEND'){
        form.addrinfo = JSON.stringify(this.itemModel.addrinfo)
      }
      request_post('/pay/order/updateExpressageNum/', form).then(res => {
        if(res.data.code == 10000){
          this.$message({
            message: '操作成功',
            type: 'success'
          })
        }
      });
    },
    getfrmTime(data){
        return data?time.dateFormat('YY-mm-dd HH:MM:SS', data):'未知'
      },
    getSpecs_sel(specList_sel) {
      //将选中的spec以,隔开
      specList_sel = JSON.parse(specList_sel)
      var specs_sel = ''
      for(var item of specList_sel){
        specs_sel = specs_sel + item.name + '，'
      }
      specs_sel = specs_sel.substring(0, specs_sel.length-1)
      return specs_sel
    },
  }
}
</script>

<style lang="scss" scoped>
.list-group {
  line-height: 1.15;
}

.show-pwd {
  position: absolute;
  right: 10px;
  top: 0px;
  font-size: 16px;
  cursor: pointer;
  user-select: none;
}

.el-carousel__item h3 {
    color: #475669;
    font-size: 14px;
    opacity: 0.75;
    line-height: 200px;
    margin: 0;
  }

  .el-carousel__item:nth-child(2n) {
    background-color: #99a9bf;
  }

  .el-carousel__item:nth-child(2n+1) {
    background-color: #d3dce6;
  }
  .photosItem{
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
  }
</style>
